/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import dao.UserDao;
import entity.User;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.WebServiceContext;

/**
 *
 * @author AnBoCa
 */
@WebService(serviceName="UserActions")
@Stateless
public class UserActions {
    
    @Resource
    private WebServiceContext wsContext;
    
    @WebMethod(operationName="doLogin")
    public boolean doLogin(@WebParam(name="user") String user, @WebParam(name="pass") String pass){
        //se buscan los datos en la bd y ser retorna true o false
        //MessageContext mc = wsContext.getMessageContext();
        //HttpSession session= ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
        //verficar en la bd
        //agregar a la session
        /*if (session==null){
            session.setAttribute("user", pass);
        }*/
        UserDao userDao = new UserDao();
        User aux=userDao.findUsuarioByUserName(user);
        if (aux!=null){
            if (aux.getPassword().equals(pass))
                return true;
        }
        return false;
    }

    @WebMethod(operationName="isUserLogin")
    public boolean isUserLogin(@WebParam(name="user") String user){
        //retorna si la session es valida
        //MessageContext mc = wsContext.getMessageContext();
        //HttpSession session= ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
        /*if (session!=null){
            if (session.getAttribute(user)!=null)
                return true;
        }*/
        return false;
    }
    
    @WebMethod(operationName="doLogout")
    public boolean doLogout(@WebParam(name="user") String user){
        //eliminar la session
        /*MessageContext mc = wsContext.getMessageContext();
        HttpSession session= ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
        if (session!=null){
            if (session.getAttribute(user)!=null){
                session.removeAttribute(user);
                return true;
            }
        }*/
        return false;
    }
    
    @WebMethod(operationName="changePassword")
    public boolean changePassword(@WebParam(name="user")String user){
        //código para cambiar la contraseña
        return false;
    }
    
}
